package leetcode.editor.cn.dsa20_heap;

import java.util.ArrayList;
import java.util.List;

/**
 * 练习，取二维数组对角线元素
 */
public class Test {
    public static void main(String[] args) {
        Test test = new Test();
        int[] nums1 = {1,2,4};
        int[] nums2 = {2,3,5};
        for (int i = 1; i < nums1.length * nums2.length; i++) {
            System.out.println(test.getNumElem(nums1, nums2, i));
        }
    }

    public List<String> getNumElem(int[] nums1, int[] nums2, int k) {
        List<String> list = new ArrayList<>();
        int i = 0, j = 0;
        while (list.size() < k) {
            String str = nums1[i] + "-" + nums2[j];
            list.add(str);
            int x = i + 1,y = j - 1;
            while (x >= 0 && x <= nums1.length-1
                    && y >=0 && y <= nums2.length - 1) {
                String temp = nums1[x++] + "-" + nums2[y--];
                list.add(temp);
            }
            if(j == nums2.length - 1) {
                i++;
            }else{
                j++;
            }
        }
        return list;
    }
}
